package nstock;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * Userinfo entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see nstock.Userinfo
 * @author MyEclipse Persistence Tools
 */

public class UserinfoDAO extends BaseHibernateDAO {
	
	// property constants
	public static final String MAIL = "mail";
	public static final String TYPE = "type";
	public static final String PASS = "pass";

	public void save(Userinfo transientInstance) {
	
		try {
			getSession().save(transientInstance);
			
		} catch (RuntimeException re) {
			
			throw re;
		}
	}

	public void delete(Userinfo persistentInstance) {
		
		try {
			getSession().delete(persistentInstance);
			
		} catch (RuntimeException re) {
			
			throw re;
		}
	}

	public Userinfo findById(java.lang.Long id) {
		
		try {
			Userinfo instance = (Userinfo) getSession().get("nstock.Userinfo",
					id);
			return instance;
		} catch (RuntimeException re) {
			
			throw re;
		}
	}

	public List findByExample(Userinfo instance) {
		
		try {
			List results = getSession().createCriteria("nstock.Userinfo")
			.add(Example.create(instance)).list();
			
			return results;
		} catch (RuntimeException re) {
			
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		
		try {
			String queryString = "from Userinfo as model where model."
				+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			
			throw re;
		}
	}

	public List findByMail(Object mail) {
		return findByProperty(MAIL, mail);
	}

	public List findByType(Object type) {
		return findByProperty(TYPE, type);
	}

	public List findByPass(Object pass) {
		return findByProperty(PASS, pass);
	}
	public int findByMailCount(Object mail)
	{ 
		return  findByMail(mail).size();
	}
	public  String findByMailPassword(Object mail)
	{
		List  l  = findByMail(mail);
		Userinfo uif =		(Userinfo) l.get(0);
		return uif.getPass();
	}
	public List findAll() {
		
		try {
			String queryString = "from Userinfo";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			
			throw re;
		}
	}

	public Userinfo merge(Userinfo detachedInstance) {
		
		try {
			Userinfo result = (Userinfo) getSession().merge(detachedInstance);
			
			return result;
		} catch (RuntimeException re) {
			
			throw re;
		}
	}

	public void attachDirty(Userinfo instance) {
		
		try {
			getSession().saveOrUpdate(instance);
			
		} catch (RuntimeException re) {
			
			throw re;
		}
	}

	public void attachClean(Userinfo instance) {

		try {
			getSession().lock(instance, LockMode.NONE);
			
		} catch (RuntimeException re) {
			
			throw re;
		}
	}
}